
import mysql.connector as mc

class Py_db_con():
    def PY_db(self,*args):
        print(args)
        try:
            com = mc.connect(
                host=args[0],
                port=args[1],
                user=args[2],
                password=args[3],
                database=args[4],
                charset="utf8"
            )

            cur = conn.cursor()
            sqlcom = "select ("customer_name","sex","name","speciality","college","create_time") from 表名'
            df = pd.read_sql(sqlcom, con=conn) print(df) print(type(df)) #<class'pandas.core.frame.DataFrame'>
            df1 = np.array(df) #先使用array()将DataFrame转换一下
            df2 = df1.tolist()#再将转换后的数据用tolist()转成列表
            # 转成列表的数据是这样的[[123],['213'],['sa']],使用的时候稍注意一下
            print(df2)
            for i in range(0, len(df2)):
                exist_url = df2[i][0]
               print(exist_url)